package com.last.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>title: com.wfx.config</p>
 * author zhuximing
 * description:
 */
@Configuration
@EnableSwagger2
@ComponentScan("com.homestay.controller")
public class Swagger2Config {

    private ApiInfo apiInfo() {
        Contact contact = new Contact("ts","","892884792@qq.com");

        return new ApiInfoBuilder().title("homestay")
            .description("homestay-平台管理系统的-api接口文档")
            .version("1.0.0")
            .contact(contact)
            .build();


    }
    @Bean
    public Docket createRestApi(Environment environment) {

        //swagger多环境配置
        //只有在dev环境或者sit环境才会显示swagger
        Profiles profiles = Profiles.of("dev","sit");
        boolean enable = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .enable(enable) // 是否开启swagger
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.homestay")) //这里写的是API接口所在的包位置
            .paths(PathSelectors.any())
            .build();
    }
}